<?
$data = date('Y-m-d H:i:s');  
if(empty($_GET["idusuario"])) {
$idusuario = -1;
}else{
	$idusuario = ($_GET["idusuario"]);
}

?>
<?
include "conexao.php";
@session_start(); // Inicializa a sessão

connect();
?>
<!--======================================================================
    BOTÃO SUPERIOR DO FORMULARIO
    ===================================================================-->
    <div class="btn-group">
     <a class="btn dropdown-toggle btn-info" data-toggle="dropdown" href="#">
     Ação
     <span class="caret"></span>
     </a>
     <ul class="dropdown-menu">
     <li><a href="usuario.php" ><i class="icon-plus icon-white"></i> usuários </a></li>
     </ul>
    </div>
        <?
          $sql = "SELECT u.nome,u.id_usuario,u.login,u.senha,s.nome_setor,s.id_setor,u.email,u.ativo,tu.id_tipo_usuario,tu.perfil 
					FROM setor s,usuario u,tipo_usuario tu
					where s.id_setor = u.id_setor and
					u.id_tipo_usuario = tu.id_tipo_usuario and
					u.id_usuario = '$idusuario'";
					
        mysql_query("SET NAMES 'utf8'");
        mysql_query('SET character_set_connection=utf8');
        mysql_query('SET character_set_client=utf8');
        mysql_query('SET character_set_results=utf8');			
		$Resultadoprecoproduto = mysql_query($sql) or die("Erro: " . mysql_error());
        while ($array_exibir = mysql_fetch_array($Resultadoprecoproduto)) 
        {
            $txtnomesolicitante= ($array_exibir['nome']);
            $txtcodusuario = ($array_exibir['id_usuario']);
            $txtlogin = ($array_exibir['login']);
            $txtsenha = ($array_exibir['senha']);
            $txtsetor = ($array_exibir['nome_setor']);
            $txtcodsetor = ($array_exibir['id_setor']);
            $txtEmail = ($array_exibir['email']);
            $txtativo = ($array_exibir['ativo']);
			if ($txtativo == 1){
				$txtativonome = "Ativo";
			}else{
				$txtativonome = "Inativo";
			}			
            $txtcodtipousuario = ($array_exibir['id_tipo_usuario']);
            $txtperfil = ($array_exibir['perfil']);
        }
             
        ?>
        
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<link href="bootstrap/css/docs.css" rel="stylesheet">
<link href="bootstrap/js/google-code-prettify/prettify.css" rel="stylesheet">
<link href="css/index.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="assets/js/html5shiv.js"></script>
<![endif]-->
<!-- jQUERY PARA VALIDAÇÃO-->
<link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css" />
<link rel="stylesheet" href="css/template.css" type="text/css" />
<script src="js/jquery-1.8.2.min.js" type="text/javascript"></script>
<script src="js/languages/jquery.validationEngine-pt_BR.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>
<!-- Fav and touch icons -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png">
<link rel="shortcut icon" href="assets/ico/favicon.png">
</head>
<script>
jQuery(document).ready(function () {  // binds form submission and fields to the validation engine
jQuery("#form1").validationEngine();
});
</script>
<body>
<form name="form1" id="form1" method="post" action="dao/usuarioinsert.php">
<!--=============================================================
    ADICIONADO USUARIOS
    =============================================================-->
	<div class="form-actions" id="formalarioadicionausuario" name="formalarioadicionausuario">
    <fieldset>
        <div class="span6">
		<? if (!empty($_GET["idusuario"])){?>
		<label><H5>Id:<?php echo $txtcodusuario;?></H5></label> 
		<?}?>
		<label>Nome: </label>
		<input class="validate[required,minSize[6]]"
        name="txtnome" value="<?php echo $txtnomesolicitante;?>" id="idtxtnome" type="text"
        placeholder="Nome do usuário" class="span10">
        <label>Login:</label> 
        
		<input name="txtlogin" value="<?php echo $txtlogin;?>" id="idtxtcodlogin" type="text" placeholder="Login" class="span10">	
		<input type="hidden" name="txtcodlogin" value="<?php echo $txtcodlogin;?>" />		
		<? if (empty($_GET["idusuario"])){?>
		<label>Senha:</label> 
        <input type="hidden" name="txtsenha" value="<?php echo $txtsenha;?>" />
		<input class="validate[required,minSize[6]]"
        name="txtsenha" value="" id="idtxtsenha" type="text"
        placeholder="Senha do usuário" class="span10">
		<?}?>
                 
        <label id="lblpesquisaprodutos">Setor</label>
     <!--==============================================================================
        COMBO-BOX DOS SETORES
        ===========================================================================-->
				<select class="validate[required]" name="cmbcategoria"
					id="idcmbcategoria">
					<option value="<?php echo $txtcodsetor;?>">
					<? echo $txtsetor ?>
					</option>
					<?
					$sql = "SELECT * FROM setor where ativo='1'";
					mysql_query("SET NAMES 'utf8'");
					mysql_query('SET character_set_connection=utf8');
					mysql_query('SET character_set_client=utf8');
					mysql_query('SET character_set_results=utf8');
					$Resultado = mysql_query($sql) or die("Erro: " . mysql_error());
					$i=0;
					$data = array();
					while ($array_exibir = mysql_fetch_array($Resultado))
					{
						?>
					<option value="<?echo $array_exibir['id_setor']?>">
					<? echo mb_strtoupper($array_exibir['nome_setor'],'UTF-8')?>
					</option>
					<?
					$i++;
					}
					?>
				</select>
        <label>Email</label> 
        <input	value="<?php echo $txtEmail;?>" class="validate[required,minSize[4]]" name="txtemail"
       id="idtxtemail" type="text" placeholder="Email do usuário" class="span12">
        <br />
        <label>Status - <? echo $txtativonome;?> </label>
		<select name="cmbativo" id="Select1">
				<option value=""></option>
				<option value="1">Ativo</option>
				<option value="2">Inativo</option>
					
		</select>
            <br />
            <br />
            <label>Tipo usuário</label>
        <select class="validate[required]" name="cmbtipousuario" id="Select2">
					<option value="<?php echo $txtcodtipousuario;?>">
					<? echo $txtperfil; ?>
					</option>
					<?
					$sql = "SELECT * FROM tipo_usuario";
					mysql_query("SET NAMES 'utf8'");
					mysql_query('SET character_set_connection=utf8');
					mysql_query('SET character_set_client=utf8');
					mysql_query('SET character_set_results=utf8');
					$Resultado = mysql_query($sql) or die("Erro: " . mysql_error());
					while ($array_exibir = mysql_fetch_array($Resultado))
					{
					?>
					<option value="<?echo $array_exibir['id_tipo_usuario']?>">
					<? echo strtoupper($array_exibir['perfil'])?>
					</option>
					<?
					$i++;
					}
					?>
		</select>		
		
        <div class="form-actions">
            <? if (empty($_GET["idusuario"])){?>
			<button type="submit" name="inserir" id="idinserir"  value="inserir" class="btn btn-success"> <i class="icon-plus icon-white"></i> Salvar </button>
			<?}else{?>
			<button type="submit" name="atualizar" id="idatualizar" value="atualizar" class="btn btn-info"> <i class="icon-refresh icon-white"></i> Atualizar</button>
			<?}?>
        </div>              
        </div>
        <div class="alert-error" id="resposta"></div>
    </fieldset>
<div id="mensagens"></div>
</div>
</form>
<script src="bootstrap/js/bootstrap-dropdown.js"></script>
</body>
</html>